package com.gastudio.Protocol;

import org.apache.mina.core.service.IoAcceptor;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.charset.Charset;

/**
 * Created by 余艾龙 on 2017/6/21.
 */
public class ProtocolServer {
    //设置端口
    static int PORT=8090;
    //
    private static IoAcceptor acceptor=null;
    public static void main(String[] args) throws IOException {
        acceptor=new NioSocketAcceptor();
        //设置过滤器,主要设置自定义协议的编解码
        acceptor.getFilterChain().addLast("codec",new ProtocolCodecFilter(new ProtocolFactory(Charset.forName("UTF-8"))));
        acceptor.getSessionConfig().setReadBufferSize(1024);
        acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE,10);
        acceptor.setHandler(new ProtocolServerHandler());
        acceptor.bind(new InetSocketAddress(PORT));
        System.out.printf("Mina Server 已启动！端口号：%s%n", PORT);
    }
}
